$(function(){
	
	var options = { 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse,  // post-submit callback 
 
        dataType:  'json',        // 'xml', 'script', or 'json' (expected server response type) 
        clearForm: false        // clear all form fields after successful submit 

    }; 
 

    $('#form_batch_order').submit(function() { 

        $(this).ajaxSubmit(options); 

        return false; 
    });

    $('#form_batch_add').submit(function() { 

    	options.clearForm = false;
    	
        $(this).ajaxSubmit(options); 

        return false; 
    }); 
    
});


function showRequest(formData, jqForm, options) { 
    //var queryString = $.param(formData); 
    return true; 
} 

function showResponse(data, statusText, xhr, $form)  {
	
	var form_id = $form.attr('id');

	if(data.success){
		alert(data.message);
				
		if(form_id == 'form_batch_add'){
			$form[0].reset();
		}
		
	}else{
		alert(data.message);
		
		if(form_id == 'form_batch_add'){
			
			var msg = '';
			for(var m in data.data){
				msg += data.data[m] + '<br />';
			}
			msg += '<a href="javascript:clear_error();" style="color:blue;">清除</a>';
			
			$('#div_error').html(msg);
		}
	}
}

function clear_error(){
	$('#div_error').html('');
}